package com.gem.day14;

import java.nio.file.*;

/**
 * 本类用来演示java nio2.0
 * 
 * JDK7.0+
 * 
 * @author easonsy
 * 2020年8月8日 上午11:05:45
 */
public class PathDemo {
	public static void main(String[] args) {
		Path src = Paths.get("D:\\day12笔记.txt");
		Path target = Paths.get("E:\\day12笔记.txt");

		/*
		 * Path在某种程度上可以当做是File,
		 * 所以JDK由于历史遗留问题提供了两者的相互转换
		 * 	File file = src.toFile();
		*	Path path = file.toPath();
		 */

		//1.Files工具类--拷贝
		/*try {
			Files.copy(src, target);
		} catch (IOException e) {
			e.printStackTrace();
		}*/

		//2.读取
		/*try {
			//List<String> lines = Files.readAllLines(src);
			//List<String> lines = Files.readAllLines(src, Charset.forName("UTF-8"));
			List<String> lines = Files.readAllLines(src, StandardCharsets.UTF_8);
			lines.forEach(System.out::println);
		} catch (IOException e) {
			e.printStackTrace();
		}*/

		//3.追加
		/*try {
			List<String> lines = Lists.newArrayList("ABCDEFG", "HelloWorld", "我是Java");
			Files.write(src, lines, StandardOpenOption.APPEND);
		} catch (IOException e) {
			e.printStackTrace();
		}*/

		//4.迭代
		try {
			DirectoryStream<Path> newDirectoryStream = Files
					.newDirectoryStream(Paths.get("C:\\Program Files\\Java\\jdk-11.0.2\\bin"), "*.dll");
			for (Path p : newDirectoryStream) {
				System.out.println(p);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
